﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Webadmin_Modules_About_ListBody : bzAdminUCBase
{
    public string _Act = "";
    public DataTable _dt = new DataTable();
    private bzDomain bz = new bzDomain();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang(bzSiteOption.Group.Administrator, bzSiteOption.Note.About, "About");
    }
    override protected void loadAction()
    {
        _Act = Request.QueryString["Act"] == null ? "" : Request.QueryString["Act"];
        if (!IsPostBack)
        {
            this.loadFRMFilter();
            switch (_Act)
            {
                case "Dis": this.active("0"); break;
                case "Ena": this.active("1"); break;
                case "Del": this.delete(); break;
                case "Save": this.save(); break;
                case "Up": this.up_down(true); break;
                case "Down": this.up_down(false); break;
            }
            this.showData();
        }

    }
    private void delete()
    {
        if (this.AllowDelete)
        {
            string chk = Request.Form["Chk"] == null ? "-1" : Request.Form["Chk"];
            string[] sID = chk.Split(',');

            int count = bz.deleteRecord(sID);
            if (count < sID.Length)
            {
                Response.Write(bzStringClass.addStringAlert(this.AdminLang["ChildrenNotEmpty"].ToString()));
                Response.Redirect(Session["Page"].ToString());
            }
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }
    private void active(string act)
    {
        if (this.AllowEdit)
        {
            string chk = Request.Form["Chk"] == null ? "-1" : Request.Form["Chk"];
            bz.activeRecord(chk.Split(','), act);
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }

    private void up_down(bool isUp)
    {
        if (this.AllowEdit)
        {
            string ID = Request.QueryString["ID"] == null ? "-1" : Request.QueryString["ID"];
            if (isUp)
                bz.upOrder(ID);
            else
                bz.downOrder(ID);

        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }
    private void save()
    {
        if (this.AllowEdit)
        {
            string chk = Request.Form["Chk"] == null ? "-1" : Request.Form["Chk"];
            string order = Request.Form["txtOrder"] == null ? "-1" : Request.Form["txtOrder"];
            bz.saveOrder(chk.Split(','), order.Split(','));
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }
    private void loadFRMFilter()
    {
        this.cboFilterEnabled.Items.Add(new ListItem(this.AdminLang["All"].ToString(), "-1"));
        this.cboFilterEnabled.Items.Add(new ListItem(this.AdminLang["Enabled"].ToString(), "1"));
        this.cboFilterEnabled.Items.Add(new ListItem(this.AdminLang["Disabled"].ToString(), "0"));

        this.cboFilterEnabled.SelectedValue = Request.QueryString["Enabled"] == null ? "-1" : Request.QueryString["Enabled"];
        this.txtFilter.Text = Request.QueryString["Keyword"] == null ? "" : Request.QueryString["Keyword"];
        this.btnFilter.Text = this.AdminLang["Filter"].ToString();
    }
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        this.showData();
    }
    private void showData()
    {
        this.SearchString = "&Keyword=" + this.txtFilter.Text + "&Enabled=" + this.cboFilterEnabled.SelectedValue;
        this.loadPagination(bz.getTotal(this.txtFilter.Text.Replace('*', '%'), this.cboFilterEnabled.SelectedValue), Convert.ToInt32(this.SiteOption["AdminLimit"]), "?" + this.SearchString);
        _dt = bz.getTable(this.txtFilter.Text.Replace('*', '%'), this.cboFilterEnabled.SelectedValue, this.CurrentPage.ToString(), this.SiteOption["AdminLimit"].ToString());
        this.Navigator = this.AdminLang["MenuHostting"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuHosttinglist"].ToString();
        this.SearchString += "&Page=" + this.CurrentPage;
    }
}
